package it.gestoreContratti.gui.frames;

import it.gestoreContratti.gui.panels.ContrattiScadenzaPanel;
import it.gestoreContratti.gui.panels.NuovaSpecificaPanel;
import it.gestoreContratti.gui.panels.VisualizzaSpecificheContrattoPanel;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class NuovaSpecificaFrame extends JFrame {

	private static final long serialVersionUID = -4131408859833746579L;
	private JPanel contentPane;	
	private ContrattiScadenzaPanel pannelloContratti;
	private VisualizzaSpecificheContrattoPanel pannelloSpecifiche;

	
	public NuovaSpecificaFrame(ContrattiScadenzaPanel contrattiPanel, VisualizzaSpecificheContrattoPanel specifichePanel) {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				if(pannelloSpecifiche == null){
					pannelloContratti.refresh();					
				}else{
					pannelloContratti.refresh();
					pannelloSpecifiche.refresh();
				}
				
			}
		});
		this.pannelloContratti = contrattiPanel;
		this.pannelloSpecifiche = specifichePanel;
		setTitle("Inserimento Nuova Specifica");
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 450, 350);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0};
		gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		NuovaSpecificaPanel nuovaSpecificaPanel = new NuovaSpecificaPanel(pannelloContratti.getDatabaseController(), pannelloContratti.getSelectedContratto());
		GridBagConstraints gbc_nuovaSpecificaPanel = new GridBagConstraints();
		gbc_nuovaSpecificaPanel.fill = GridBagConstraints.BOTH;
		gbc_nuovaSpecificaPanel.gridx = 0;
		gbc_nuovaSpecificaPanel.gridy = 0;
		contentPane.add(nuovaSpecificaPanel, gbc_nuovaSpecificaPanel);
	}

}
